package com.da.lon.wang.xlg.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;

import com.da.lon.wang.xlg.R;
import com.umeng.analytics.MobclickAgent;

import org.json.JSONObject;

import cn.jpush.android.api.JPushInterface;

public class JpushActivity extends BaseActivity implements OnClickListener {

    private TextView jpush_messages_tv;
    private TextView titleView;
    private ImageButton backButton;
    private Intent intents;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ouka_jpush_activity);
        initView();
    }

    private void initView() {
        try {
            titleView = (TextView) findViewById(R.id.title);
            backButton = (ImageButton) findViewById(R.id.ouka_home_buyer_left);
            backButton.setOnClickListener(this);
            jpush_messages_tv = (TextView) findViewById(R.id.jpush_messages_tv);
            Intent intent = getIntent();
            if (null != intent) {
                Bundle bundle = getIntent().getExtras();
                String title = bundle
                        .getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
                String content = bundle.getString(JPushInterface.EXTRA_ALERT);
                String extra_extra = bundle
                        .getString(JPushInterface.EXTRA_EXTRA);
                JSONObject object = new JSONObject(extra_extra);
                String ocoffee_url = object.optString("ocoffee_url");
                if (!ocoffee_url.equals("")) {
                    intents = new Intent(this, WebViewActivity.class);
                    Bundle bundlel = new Bundle();
                    bundlel.putInt("flag", 002);
                    bundlel.putString("url", ocoffee_url);
                    intents.putExtras(bundlel);
                    startActivity(intents);
                    JpushActivity.this.finish();
                } else {
                    jpush_messages_tv.setText(content);
                }

                if (null != title && !title.trim().equals("")) {
                    titleView.setText(title);
                } else {
                    titleView.setText("消息");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ouka_home_buyer_left:
                finish();
                break;

        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }
}
